let span = document.querySelector(".inputop-1")
let num = 0
let btn = document.querySelector(".register-rightnow")

span.onclick = function () {
    num++
    if (num % 2 == 1) {
        span.style.background = "#00bdff"
        btn.style.background = "#00bdff"
    } else {
        span.style.background = "none"
        btn.style.background = "#767676"
    }
}

let ittsArr = document.querySelectorAll(".itts")
let ittArr = document.querySelectorAll(".itt")
let ittpArr = document.querySelectorAll(".ittp")
let reBtn = document.querySelector(".register-rightnow")
let inputArr = document.querySelectorAll(".input-text")
let regArr = [
    /^[a-zA-Z]\w{5,11}$/,   //6-12: 字母开头,后面跟字母\数字\下划线
    /^1[3456789][0-9]{9}$/, //11  : 
    /^[a-zA-Z]\w{3}$/,      //4位验证码: 字母开头,后面跟字母\数字\下划线
    /^[a-zA-Z]\w{5,11}$/    //6-12: 字母开头,后面跟字母\数字\下划线
]

ittArr.forEach(function (v, i) {
    ittsArr[i].style.display = "none"
    v.oninput = function () {
        if (ittArr[i].children[0].value.length > 0) {
            ittsArr[i].style.display = "block"
        } else {
            ittsArr[i].style.display = "none"
        }
    }
    ittArr[i].children[0].onblur = function (){
        let bol = regArr[i].test(ittArr[i].children[0].value)
        if (bol) {
            ittpArr[i].style.display = "none"
        } else {
            ittpArr[i].style.display = "block"
        }
    }

    
})

span.onclick = function () {
    num++
    if (num % 2 == 1) {
        span.style.background = "#00bdff"
        btn.style.background = "#00bdff"
        reBtn.disabled = false
        reBtn.onclick = function (){
            let flag = true
            ittArr.forEach(function (v,i){
                let bol = regArr[i].test(ittArr[i].children[0].value)
                if (bol) {
                    ittpArr[i].style.display = "none"
                } else {
                    ittpArr[i].style.display = "block"
                    flag = false
                }
            })
            if (flag) {
                let obj1 = {
                    username: inputArr[0].value,
                    phone: inputArr[1].value,
                    review: inputArr[2].value,
                    psw: inputArr[3].value,
                }
            console.log(obj1);
            alert("注册成功")
            // return false
            }
        }

    } else if (num % 2 == 0){
        span.style.background = "none"
        btn.style.background = "#e0e0e0"
        reBtn.disabled = true
    }
}

ittsArr.forEach(function (v2, i2) {
    v2.onclick = function () {
        ittArr[i2].children[0].value = ""
        ittsArr[i2].style.display = "none"
    }
})

